package com.springmvc.demo;

import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;

// 地址识别 示例代码
public class ApiDemo {

    public static void main(String[] args) {
        String path = "https://aip.baidubce.com/rpc/2.0/nlp/v1/address";
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.POST, path);


        // 设置header参数
        request.addHeaderParameter("Content-Type", "application/json;charset=UTF-8");

        // 设置query参数
        request.addQueryParameter("access_token", "24.645edcad8392b8cefccfdaa1fbd441f6.2592000.1637137577.282335-25011312");

        // 设置jsonBody参数
        String jsonBody = "{\"text\": \"上海市浦东新区纳贤路701号百度上海研发中心 F4A000 张三\", \"confidence\": 100}";
        request.setJsonBody(jsonBody);

        ApiExplorerClient client = new ApiExplorerClient();

        try {
            ApiExplorerResponse response = client.sendRequest(request);
            // 返回结果格式为Json字符串
            System.out.println(response.getResult());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
